#include <iostream>

using namespace std;

template<class T>
class QUEUE
{
public:
    QUEUE(const int &number):capacity(number)
    {
        data=(T*)new T[number];
        head=0;
        rear=0;
        capacity=rear-head;
    };
    ~QUEUE()
    {
       delete []data;
    };
    int size();
    T& front();
    T& back();
    void push(const T &element);
    void pop();
    void display();
private:
    int capacity;
    T* data;
    int head;
    int rear;
};

template<class T>
int QUEUE<T>::size()
{
    return (rear-head);;
};

template<class T>
void QUEUE<T>::push(const T &element)
{
    *(data+rear)=element;
    rear++;  //comment the rear have been added once more;
};

template<class T>
void QUEUE<T>::pop()
{
    head++;
};

template<class T>
void QUEUE<T>::display()
{
    int begin=head;
    for(int i=begin;i<rear;i++)
    {
        cout<<*(data+i)<<"  ";
    }
    cout<<endl;
};

template<class T>
T& QUEUE<T>::front()
{
    return *(data+head);
};

template<class T>
T& QUEUE<T>::back()
{
    return *(data+rear-1);
};

int main()
{
    QUEUE<int> a(10);
    for(int i=1;i<=5;i++)
    {
        a.push(i*2);
    }
    a.display();
    cout<<a.size()<<endl;

    a.pop();
    a.display();
    cout<<a.size()<<endl;
    cout<<"the head of the queue is "<<a.front()<<endl;
    cout<<"the end of the queue is "<<a.back()<<endl;

    system("pause");
    return 0;
}

